import utilClass.Node;
import utilClass.TreeNode;

public class SumRootToLeaf {

    public int getToleaf(TreeNode treeNode){
        return dfs(treeNode,0);
    }

    public int dfs(TreeNode root,int val){
        if(root==null){
            return 0;
        }
        val = (val << 1) | root.val;
        if (root.left == null && root.right == null) {
            return val;
        }
        return dfs(root.left,val)+dfs(root.right,val);
    }
}



